<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增出库日志')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-erpStockOutLog-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">出库批次号：</label>
                <div class="col-sm-8">
                    <input name="batchNo" readonly onclick="openSelectBatch()" class="form-control" placeholder="点击选择" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">订单号：</label>
                <div class="col-sm-8">
                    <input name="orderNo" readonly class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">客户编号：</label>
                <div class="col-sm-8">
                    <input name="customerNo" readonly class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">生产型号：</label>
                <div class="col-sm-8">
                    <input name="modeNo" readonly class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">出库数量：</label>
                <div class="col-sm-8">
                    <input name="outNum" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">出库时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="outTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">配送方式：</label>
                <div class="col-sm-8">
                    <select name="deliveryWay" class="form-control m-b" th:with="type=${@dict.getType('erp_deliveryWay')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">物流公司：</label>
                <div class="col-sm-8">
                    <input name="logisticsCompany" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">物流公司编码：</label>
                <div class="col-sm-8">
                    <input name="logisticsCompanyCode" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">物流编号：</label>
                <div class="col-sm-8">
                    <input name="logisticsNo" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">收货地址：</label>
                <div class="col-sm-8">
                    <input name="consigneeId" type="hidden">
                    <input name="consigneeIdLabel" readonly onclick="openSelectConsignee()" class="form-control" placeholder="点击选择" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "erp/erpStockOutLog"
        $("#form-erpStockOutLog-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-erpStockOutLog-add').serialize());
            }
        }

        $("input[name='outTime']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            todayBtn: true,
            todayHighlight: true,
            keyboardNavigation: true,
            minuteStep: 1,
            autoclose: true
        });

        // 选择批次
        function openSelectBatch() {
            var url = ctx + "../../erp/erpBatchInfo/pageSelectBatch";
            var options = {
                title: '选择批次号',
                url: url,
                width: 1200,
                callBack: doSelectBatchSubmit
            };
            $.modal.openOptions(options);
        }

        function doSelectBatchSubmit(index, layero) {
            var body = layer.getChildFrame('body', index);
            var batchNo = body.find('#batchNo').val();
            var orderNo = body.find('#orderNo').val();
            var modeNo = body.find('#modeNo').val();
            var customerNo = body.find('#customerNo').val();
            layer.close(index);
            if (batchNo != "" && batchNo != undefined) {
                $("input[name='batchNo']").val(batchNo);
                $("input[name='orderNo']").val(orderNo);
                $("input[name='modeNo']").val(modeNo);
                $("input[name='customerNo']").val(customerNo);
            }
        }

        // 选择收货地址
        function openSelectConsignee() {
            var url = ctx + "../../erp/erpConsigneeInfo/pageSelectConsignee";
            var options = {
                title: '选择收货地址',
                url: url,
                width: 1200,
                callBack: doSelectConsigneeSubmit
            };
            $.modal.openOptions(options);
        }

        function doSelectConsigneeSubmit(index, layero) {
            var body = layer.getChildFrame('body', index);
            var consigneeId = body.find('#consigneeId').val();
            var consignee = body.find('#consignee').val();
            var consigneePhone = body.find('#consigneePhone').val();
            var address = body.find('#address').val();
            layer.close(index);
            if (consigneeId != "" && consigneeId != undefined) {
                $("input[name='consigneeId']").val(consigneeId);
                // $("input[name='consignee']").val(consignee);
                // $("input[name='address']").val(address);
                $("input[name='consigneeIdLabel']").val(consignee + '-' + consigneePhone + '-' + address);
            }
        }
    </script>
</body>
</html>